package com.gexiaobao.pigeon.ui.adapter

import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.ReceiptPigeonResponse
import com.gexiaobao.pigeon.databinding.ItemReceiptPigeonBinding

/**
 * @Author      : hxw
 * @Date        : 2024/5/31 15:32
 * @Describe    :
 */
class AdapterReceiptPigeon(data: ArrayList<ReceiptPigeonResponse.ListBean>) :
    BaseQuickAdapter<ReceiptPigeonResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_receipt_pigeon, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: ReceiptPigeonResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemReceiptPigeonBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        var tvAddress = ""
        val address = item.address
        tvAddress = if (address.length <= 3) {
            address
        } else if (address.length in 4..6) {
            address.substring(0, 3) + "\n" + address.substring(3, address.length - 1)
        } else if (address.length > 6) {
            address.substring(0, 3) + "\n" + address.substring(3, 6) + "\n" + address.substring(6, address.length - 1)
        } else {
            "--"
        }
        holder.setText(R.id.tvItemReceiptAddress, tvAddress)

        if (holder.layoutPosition % 2 == 0) {
            holder.setBackgroundColor(R.id.llItemReceiptPigeon, ContextCompat.getColor(context, org.angmarch.views.R.color.light_gray))
        } else {
            holder.setBackgroundColor(R.id.llItemReceiptPigeon, ContextCompat.getColor(context, R.color.white))
        }
    }
}